using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Interop;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Converters;
using System.Windows.Media.Composition;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using System.Windows.Shapes;
using System.Runtime.InteropServices;

namespace Sidebar
{

    public class ClockGadget : GadgetBase.GadgetWindow
    {
        FlyoutClass flc = new FlyoutClass();

        public ClockGadget()
            : base(@"sampleImages\Gadget.png")
        {
            LHClock lhClock = new LHClock();
            //base.Children.Add(lhClock);

            base.Content = lhClock;

            base.MouseUp += new MouseButtonEventHandler(this.ClockGadget_MouseUp);
        }

        private void ClockGadget_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Right)
            {
                Flyout.showFlyout(this, flc);               
            }
        }


    }

    public class LHClock : StackPanel
    {
        // Fields
        private TextBlock time;

        // Methods
        public LHClock()
        {
            base.Orientation = Orientation.Horizontal;
            base.Height = 70.0;
            base.Width = 165.0;
            Clock visual = new Clock(false);
            visual.LayoutTransform = new ScaleTransform(0.7, 0.7);
            visual.Margin = new Thickness(5.0, 0.0, 0.0, 0.0);
            Rectangle rectangle = new Rectangle();
            rectangle.Margin = new Thickness(4.0, 2.0, 4.0, 2.0);
            rectangle.Fill = new VisualBrush(visual);
            base.Children.Add(visual);
            this.time = new TextBlock();
            this.time.FontSize = 10.7;
            this.time.Text = DateTime.Now.ToString("hh:mm ") + ((DateTime.Now.Hour > 12) ? "PM" : "AM") + "\n" + DateTime.Now.ToString("dddd\nMMMM dd, yyyy");
            this.time.Foreground = Brushes.White;
            this.time.VerticalAlignment = VerticalAlignment.Center;
            this.time.HorizontalAlignment = HorizontalAlignment.Center;
            this.time.Padding = new Thickness(2.0, 0.0, 3.0, 0.0);
            base.Children.Add(this.time);
            visual.MinuteChanging += new Clock.TimeRefreshDelegate(this.timer_Tick);
        }

        private void timer_Tick()
        {
            this.time.Text = DateTime.Now.ToString("hh:mm ") + ((DateTime.Now.Hour > 12) ? "PM" : "AM") + "\n" + DateTime.Now.ToString("dddd\nMMMM dd, yyyy");
        }
    }


    public class Clock : Canvas
    {
        // Fields
        private int _hourrefreshdelay;
        private Canvas bobble;
        private RotateTransform hours;
        private RotateTransform minutes;
        private RotateTransform seconds;
        public DispatcherTimer timer;

        // Events
        public event TimeRefreshDelegate HourChanging;

        public event TimeRefreshDelegate MinuteChanging;

        // Methods
        public Clock(bool showbobble)
        {
            base.Height = 80.0;
            base.Width = 80.0;
            Binding binding = new Binding("Height");
            binding.Source = this;
            Binding binding2 = new Binding("Width");
            binding2.Source = this;
            string str = UsefulMethods.getTileDllPath();
            Image element = new Image();
            element.Source = new BitmapImage(new Uri(str + @"\clockface.png"));
            element.Stretch = Stretch.UniformToFill;
            element.SetBinding(FrameworkElement.HeightProperty, binding);
            element.SetBinding(FrameworkElement.WidthProperty, binding2);
            Image image2 = new Image();
            image2.Source = new BitmapImage(new Uri(str + @"\second.png"));
            image2.Height = 0.0 * base.Height;
            image2.Width = 0.0 * base.Width;
            Image image3 = new Image();
            image3.Source = new BitmapImage(new Uri(str + @"\minute.png"));
            image3.Height = 38.0;
            image3.Width = 5.0;
            Image image4 = new Image();
            image4.Source = new BitmapImage(new Uri(str + @"\hour.png"));
            image4.Height = 29.0;
            image4.Width = 5.0;
            Image image5 = new Image();
            image5.Source = new BitmapImage(new Uri(str + @"\clockHL.png"));
            image5.SetBinding(FrameworkElement.HeightProperty, binding);
            image5.SetBinding(FrameworkElement.WidthProperty, binding2);
            Image image6 = new Image();
            image6.Source = new BitmapImage(new Uri(str + @"\hub.png"));
            image6.Height = 0.0 * base.Height;
            image6.Width = 0.0 * base.Width;
            base.Children.Add(element);
            base.Children.Add(image3);
            base.Children.Add(image4);
            base.Children.Add(image2);
            base.Children.Add(image6);
            base.Children.Add(image5);
            Canvas.SetTop(element, 0.0);
            Canvas.SetTop(image5, 0.0);
            Canvas.SetTop(image2, 12.0);
            Canvas.SetTop(image3, 12.0);
            Canvas.SetTop(image4, 20.0);
            Canvas.SetTop(image6, 38.25);
            Canvas.SetLeft(element, 0.0);
            Canvas.SetLeft(image5, 0.0);
            Canvas.SetLeft(image4, 37.5);
            Canvas.SetLeft(image3, 37.5);
            Canvas.SetLeft(image2, 37.5);
            Canvas.SetLeft(image6, 38.0);
            this.seconds = new RotateTransform();
            image2.RenderTransformOrigin = new Point(0.5, 0.75);
            this.seconds.Angle = DateTime.Now.Second * 6;
            image2.RenderTransform = this.seconds;
            this.minutes = new RotateTransform();
            image3.RenderTransformOrigin = new Point(0.5, 0.75);
            this.minutes.Angle = DateTime.Now.Minute * 6;
            image3.RenderTransform = this.minutes;
            this.hours = new RotateTransform();
            image4.RenderTransformOrigin = new Point(0.5, 0.7);
            this.hours.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5);
            image4.RenderTransform = this.hours;
            this.timer = new DispatcherTimer();
            this.timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            this.timer.Tick += new EventHandler(this.timer_Tick);
            this.timer.IsEnabled = true;
            if (showbobble)
            {
                this.bobble = new Canvas();
                this.bobble.Height = base.Height / 2.0;
                this.bobble.Width = 13.0;
                Panel.SetZIndex(this.bobble, 10);
                Canvas.SetTop(this.bobble, 5.0);
                Canvas.SetLeft(this.bobble, (base.Width / 2.0) - 6.5);
                base.Children.Add(this.bobble);
            }
        }

        private void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            AdornerLayer.GetAdornerLayer(this).Add(new AlarmBobbleAdorner(this.bobble));
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.seconds.Angle = DateTime.Now.Second * 6;
            if (this.minutes.Angle != (DateTime.Now.Minute * 6))
            {
                this._hourrefreshdelay++;
            }
            if ((this.seconds.Angle > 350.0) || (this.seconds.Angle < 15.0))
            {
                this.minutes.Angle = DateTime.Now.Minute * 6;
                this.MinuteChanging();
            }
            if (this._hourrefreshdelay == 6)
            {
                this.hours.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5);
                this._hourrefreshdelay = 0;
            }
        }

        // Nested Types
        public delegate void TimeRefreshDelegate();
    }

    public class AlarmBobbleAdorner : Adorner
    {
        // Fields
        private Thumb bobble;
        private ImageBrush bobblebrush;
        private Style thumbstyle;
        private VisualCollection visualChildren;

        // Methods
        public AlarmBobbleAdorner(UIElement adornedelement)
            : base(adornedelement)
        {
            this.thumbstyle = (Style)Application.LoadComponent(new Uri("/ClockTile;component/ThumbStyle.xaml", UriKind.Relative));
            this.visualChildren = new VisualCollection(this);
            string directoryName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            this.bobblebrush = new ImageBrush(new BitmapImage(new Uri(directoryName + @"\AlarmBobble.png")));
            this.bobble = new Thumb();
            this.bobble.Style = this.thumbstyle;
            this.bobble.Background = this.bobblebrush;
            this.visualChildren.Add(this.bobble);
            this.bobble.DragDelta += new DragDeltaEventHandler(this.bobble_DragDelta);
        }

        protected override Size ArrangeOverride(Size finalSize)
        {
            this.bobble.Arrange(new Rect(0.0, 0.0, 13.0, 12.0));
            return finalSize;
        }

        private void bobble_DragDelta(object sender, DragDeltaEventArgs e)
        {
            this.bobble.ClipToBounds = true;
            RotateTransform transform = new RotateTransform();
            double height = ((FrameworkElement)base.AdornedElement).Height;
            transform.Angle += e.VerticalChange;
            transform.CenterY = height;
            transform.CenterX = height;
            Canvas adornedElement = (Canvas)base.AdornedElement;
            Canvas.SetTop(base.AdornedElement, Canvas.GetTop(base.AdornedElement) + e.VerticalChange);
            Canvas.SetLeft(base.AdornedElement, Canvas.GetLeft(base.AdornedElement) + e.HorizontalChange);
        }

        protected override Visual GetVisualChild(int index)
        {
            return this.visualChildren[index];
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            Rect rect = new Rect(0.0, 0.0, 13.0, 12.0);
            ImageDrawing drawing = new ImageDrawing(this.bobblebrush.ImageSource, rect);
        }

        // Properties
        protected override int VisualChildrenCount
        {
            get
            {
                return this.visualChildren.Count;
            }
        }
    }


    public class FlyoutClass : Canvas
    {
        // Fields
        private TextBlock AMPM = new TextBlock();
        private Grid calendar = new Grid();
        private Clock clock = new Clock(false);
        private RowDefinition image = new RowDefinition();
        private TextBlock textTime = new TextBlock();

        // Methods
        public FlyoutClass()
        {
            base.Height = 330.0;
            base.Width = 510.0;
            this.clock.LayoutTransform = new ScaleTransform(3.25, 3.25);
            this.clock.MinuteChanging += new Clock.TimeRefreshDelegate(this.clock_MinuteChanging);
            this.textTime.Text = DateTime.Now.ToString("hh:mm ");
            this.textTime.Foreground = Brushes.White;
            this.textTime.FontFamily = new FontFamily("Segoe UI");
            this.textTime.FontSize = 24.0;
            this.AMPM.Foreground = new SolidColorBrush(Color.FromRgb(0xcb, 230, 0xfb));
            this.AMPM.Text = (DateTime.Now.Hour >= 12) ? "PM" : "AM";
            this.AMPM.FontSize = 24.0;
            this.AMPM.FontFamily = new FontFamily("Segoe UI");
            this.textTime.Inlines.Add(this.AMPM);
            this.textTime.SnapsToDevicePixels = true;
            this.calendar.RowDefinitions.Add(this.image);
            this.calendar.Height = 290.0;
            this.calendar.Width = 220.0;
            this.calendar.Background = Brushes.White;
            this.calendar.Clip = new RectangleGeometry(new Rect(0.0, 0.0, 220.0, 290.0), 2.5, 2.5);
            this.setupCalendar(ref this.calendar);
            Border element = new Border();
            element.Child = this.calendar;
            element.CornerRadius = new CornerRadius(2.5);
            element.BorderBrush = Brushes.Black;
            element.BorderThickness = new Thickness(1.0);
            base.Children.Add(this.clock);
            base.Children.Add(this.textTime);
            base.Children.Add(element);
            Canvas.SetTop(this.clock, 20.0);
            Canvas.SetLeft(this.clock, 10.0);
            Canvas.SetLeft(this.textTime, 98.0);
            Canvas.SetBottom(this.textTime, 14.0);
            Canvas.SetRight(element, 10.0);
            Canvas.SetTop(element, 20.0);
        }

        private void clock_MinuteChanging()
        {
            this.textTime.Text = DateTime.Now.ToString("hh:mm ");
            this.textTime.Foreground = Brushes.White;
            this.textTime.FontFamily = new FontFamily("Segoe UI");
            this.textTime.FontSize = 24.0;
            this.AMPM = new TextBlock();
            this.AMPM.Text = (DateTime.Now.Hour >= 12) ? "PM" : "AM";
            this.AMPM.Foreground = new SolidColorBrush(Color.FromRgb(0xcb, 230, 0xfb));
            this.AMPM.FontSize = 24.0;
            this.AMPM.FontFamily = new FontFamily("Segoe UI");
            this.textTime.Inlines.Add(this.AMPM);
        }

        private void setupCalendar(ref Grid cal)
        {
            FlyoutCalender element = new FlyoutCalender();
            this.calendar.Children.Add(element);
            Grid.SetRow(element, 0);
        }

        // Nested Types
        internal class FlyoutCalender : Grid
        {
            // Fields
            private Button back;
            private SolidColorBrush Bdisable;
            private SolidColorBrush Bheader;
            private SolidColorBrush Bnorm;
            private Image calimg;
            private Grid calspace;
            private DateTime dt;
            private Button fwd;
            private TextBlock month;
            private int offset;
            private string thisFolder;

            // Methods
            public FlyoutCalender()
            {
                int num;
                this.dt = DateTime.Now;
                this.offset = 0;
                this.thisFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                this.calimg = new Image();
                this.calimg.Height = 110.0;
                string uriString = string.Concat(new object[] { this.thisFolder, @"\CalendarImages\", DateTime.Now.Month, ".png" });
                this.calimg.Source = new BitmapImage(new Uri(uriString));
                this.calimg.Stretch = Stretch.UniformToFill;
                base.Children.Add(this.calimg);
                Grid.SetRow(this.calimg, 0);
                Grid.SetColumnSpan(this.calimg, 9);
                this.calspace = new Grid();
                for (num = 0; num < 6; num++)
                {
                    this.calspace.RowDefinitions.Add(new RowDefinition());
                    this.calspace.ColumnDefinitions.Add(new ColumnDefinition());
                }
                this.calspace.ColumnDefinitions.Add(new ColumnDefinition());
                base.RowDefinitions.Add(new RowDefinition());
                base.RowDefinitions[0].Height = new GridLength(110.0);
                base.RowDefinitions.Add(new RowDefinition());
                base.RowDefinitions[1].Height = new GridLength(30.0);
                base.RowDefinitions.Add(new RowDefinition());
                base.RowDefinitions[2].Height = new GridLength(15.0);
                base.RowDefinitions.Add(new RowDefinition());
                base.RowDefinitions[3].Height = GridLength.Auto;
                for (num = 0; num < 9; num++)
                {
                    base.ColumnDefinitions.Add(new ColumnDefinition());
                }
                base.SnapsToDevicePixels = true;
                this.Bheader = new SolidColorBrush(Color.FromArgb(0xff, 170, 0xb2, 0xd6));
                this.Bnorm = new SolidColorBrush(Color.FromArgb(0xff, 0, 0, 0));
                this.Bdisable = Brushes.LightGray;
                this.month = new TextBlock();
                this.month.Foreground = this.Bheader;
                this.month.Text = this.dt.ToString("Y");
                this.month.HorizontalAlignment = HorizontalAlignment.Center;
                this.month.VerticalAlignment = VerticalAlignment.Center;
                this.month.FontWeight = FontWeights.SemiBold;
                DockPanel element = new DockPanel();
                this.back = new Button();
                this.back.Opacity = 0.0;
                this.back.Content = "<<";
                element.Children.Add(this.back);
                DockPanel.SetDock(this.back, Dock.Left);
                this.back.Click += new RoutedEventHandler(this.back_Click);
                this.fwd = new Button();
                this.fwd.Opacity = 0.0;
                this.fwd.Content = ">>";
                element.Children.Add(this.fwd);
                DockPanel.SetDock(this.fwd, Dock.Right);
                this.fwd.Click += new RoutedEventHandler(this.fwd_Click);
                element.Children.Add(this.month);
                element.MouseEnter += new MouseEventHandler(this.month_MouseEnter);
                element.MouseLeave += new MouseEventHandler(this.month_MouseLeave);
                base.Children.Add(element);
                Grid.SetRow(element, 1);
                Grid.SetColumn(element, 1);
                Grid.SetColumnSpan(element, 7);
                for (num = 0; num < 7; num++)
                {
                    TextBlock block = new TextBlock();
                    block.Foreground = this.Bheader;
                    block.Text = ((DayOfWeek)num).ToString().Substring(0, 3);
                    block.HorizontalAlignment = HorizontalAlignment.Center;
                    block.VerticalAlignment = VerticalAlignment.Center;
                    block.FontSize = 11.0;
                    base.Children.Add(block);
                    Grid.SetRow(block, 2);
                    Grid.SetColumn(block, num + 1);
                    Grid.SetColumnSpan(block, 1);
                }
                if (this.dt.Day != 1)
                {
                    this.dt = this.dt.Subtract(new TimeSpan(this.dt.Day, 0, 0, 0));
                }
                for (num = 0; num < 7; num++)
                {
                    if (this.dt.DayOfWeek != DayOfWeek.Sunday)
                    {
                        this.dt = this.dt.Subtract(new TimeSpan(1, 0, 0, 0));
                    }
                }
                this.fillCalGrid(this.calspace, this.dt, DateTime.Now.Month);
                base.Children.Add(this.calspace);
                Grid.SetRow(this.calspace, 3);
                Grid.SetColumn(this.calspace, 1);
                Grid.SetColumnSpan(this.calspace, 7);
            }

            private void back_Click(object sender, RoutedEventArgs e)
            {
                this.calspace.Children.Clear();
                DateTime now = DateTime.Now;
                this.offset--;
                now = now.AddMonths(this.offset);
                int month = now.Month;
                this.month.Text = now.ToString("Y");
                string uriString = string.Concat(new object[] { this.thisFolder, @"\CalendarImages\", now.Month, ".png" });
                this.calimg.Source = new BitmapImage(new Uri(uriString));
                if (now.Day != 1)
                {
                    now = now.Subtract(new TimeSpan(now.Day - 1, 0, 0, 0));
                }
                for (int i = 0; i < 7; i++)
                {
                    if (now.DayOfWeek != DayOfWeek.Sunday)
                    {
                        now = now.Subtract(new TimeSpan(1, 0, 0, 0));
                    }
                }
                this.fillCalGrid(this.calspace, now, month);
            }

            private void fillCalGrid(Grid backgrid, DateTime dt, int focusmonth)
            {
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        TextBlock element = new TextBlock();
                        element.Text = dt.Day.ToString();
                        element.Foreground = (dt.Month == focusmonth) ? this.Bnorm : this.Bdisable;
                        element.HorizontalAlignment = HorizontalAlignment.Center;
                        element.VerticalAlignment = VerticalAlignment.Center;
                        element.FontSize = 12.0;
                        if (((dt.Day == DateTime.Now.Day) && (DateTime.Now.Month == focusmonth)) && (focusmonth == dt.Month))
                        {
                            element.FontWeight = FontWeights.SemiBold;
                            Border border = new Border();
                            border.Height = 15.0;
                            border.Width = 23.0;
                            border.Background = new SolidColorBrush(Color.FromArgb(150, 0xff, 0xe8, 0xb1));
                            border.CornerRadius = new CornerRadius(3.0);
                            border.BorderBrush = new SolidColorBrush(Color.FromArgb(110, 0xf6, 0x99, 0x36));
                            border.BorderThickness = new Thickness(1.0);
                            backgrid.Children.Add(border);
                            Grid.SetColumn(border, j);
                            Grid.SetRow(border, i);
                        }
                        backgrid.Children.Add(element);
                        Grid.SetColumn(element, j);
                        Grid.SetRow(element, i);
                        dt = dt.AddDays(1.0);
                    }
                }
            }

            private void fwd_Click(object sender, RoutedEventArgs e)
            {
                this.calspace.Children.Clear();
                DateTime now = DateTime.Now;
                this.offset++;
                now = now.AddMonths(this.offset);
                int month = now.Month;
                this.month.Text = now.ToString("Y");
                string uriString = string.Concat(new object[] { this.thisFolder, @"\CalendarImages\", now.Month, ".png" });
                this.calimg.Source = new BitmapImage(new Uri(uriString));
                if (now.Day != 1)
                {
                    now = now.Subtract(new TimeSpan(now.Day - 1, 0, 0, 0));
                }
                for (int i = 0; i < 7; i++)
                {
                    if (now.DayOfWeek != DayOfWeek.Sunday)
                    {
                        now = now.Subtract(new TimeSpan(1, 0, 0, 0));
                    }
                }
                this.fillCalGrid(this.calspace, now, month);
            }

            private void month_MouseEnter(object sender, MouseEventArgs e)
            {
                DoubleAnimation animation = new DoubleAnimation(1.0, new Duration(new TimeSpan(0, 0, 0, 0, 500)));
                this.back.BeginAnimation(UIElement.OpacityProperty, animation);
                this.fwd.BeginAnimation(UIElement.OpacityProperty, animation);
            }

            private void month_MouseLeave(object sender, MouseEventArgs e)
            {
                DoubleAnimation animation = new DoubleAnimation(0.0, new Duration(new TimeSpan(0, 0, 0, 0, 500)));
                this.back.BeginAnimation(UIElement.OpacityProperty, animation);
                this.fwd.BeginAnimation(UIElement.OpacityProperty, animation);
            }
        }
    }


    internal class Pin : Canvas
    {
        // Fields
        private Popup flyout;
        private const double height = 15.0;
        private HwndSource hs;
        private bool isPinned = true;
        private const int SC_MOVE = 0xf010;
        private const double width = 15.0;
        private const int WM_SYSCOMMAND = 0x112;

        // Methods
        public Pin(Popup slave)
        {
            this.flyout = slave;
            base.Height = 15.0;
            base.Width = 15.0;
            base.Loaded += new RoutedEventHandler(this.Pin_Loaded);
            base.MouseUp += new MouseButtonEventHandler(this.Pin_MouseUp);
            base.Children.Add(this.makeArrow());
        }

        private void flyout_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if ((e.ChangedButton == MouseButton.Left) && (e.OriginalSource.GetType() != typeof(Path)))
            {
                IntPtr handle = this.hs.Handle;
                ReleaseCapture();
                SendMessage(handle, 0x112, 0xf012, 0);
                e.Handled = true;
            }
        }

        public Path makeArrow()
        {
            Path path = new Path();
            path.Data = Geometry.Parse("M 15,5 L 7.5,5 L 7.5,0 L 0,7.5 L 7.5,15 L 7.5,10 L 15,10 L 15,5");
            path.Fill = Brushes.LightGray;
            return path;
        }

        public Path makeCross()
        {
            Path path = new Path();
            path.Data = Geometry.Parse("M 3.25,0 L 7.5,5.5 L 10.75,0 L 15,3.25 L 9.5,7.5 L 15,10.75 L 10.75,15 L 7.5,9.5 L 3.75,15 L 0,10.75 L 5.5,7.5 L 0,3.25 L 3.25,0");
            path.Fill = Brushes.DarkRed;
            path.Stroke = Brushes.Black;
            path.StrokeThickness = 1.0;
            return path;
        }

        private void Pin_Loaded(object sender, RoutedEventArgs e)
        {
            this.hs = (HwndSource)PresentationSource.FromVisual(this.flyout.Child);
        }

        private void Pin_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                Point point;
                if (this.isPinned)
                {
                    this.flyout.StaysOpen = true;
                    this.isPinned = false;
                    this.flyout.MouseDown += new MouseButtonEventHandler(this.flyout_MouseDown);
                    base.Children.Clear();
                    base.Children.Add(this.makeCross());
                    point = base.PointToScreen(new Point(0.0, 0.0));
                    SetWindowPos(this.hs.Handle, -2, ((int)point.X) - ((int)this.flyout.Child.RenderSize.Width), (int)point.Y, 0, 0, 0x200);
                }
                else
                {
                    point = base.PointToScreen(new Point(0.0, 0.0));
                    SetWindowPos(((HwndSource)PresentationSource.FromVisual(Application.Current.MainWindow)).Handle, -1, ((int)point.X) - ((int)this.flyout.Child.RenderSize.Width), (int)point.Y, 0, 0, 3);
                    this.flyout.IsOpen = false;
                }
                e.Handled = true;
            }
        }

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [DllImport("user32")]
        private static extern int SetWindowPos(IntPtr hwnd, int hwndInsertAfter, int x, int y, int cx, int cy, int wFlags);
    }





}
